package com.cn.wanxi.service;

import com.cn.wanxi.IO.FileModelIO;
import com.cn.wanxi.IOModel.ProductIOModel;
import com.cn.wanxi.IOModel.ProductTypeIOModel;
import com.cn.wanxi.model.ProductTypeModel;
import com.cn.wanxi.util.IOUtil;

import java.util.List;

public class ProductTypeService {
    public List<ProductTypeModel> getProductTypeList(){
        FileModelIO.writeData(IOUtil.PRODUCTTYPEPATH.getPath(),new ProductTypeIOModel().toString());
        String result = FileModelIO.readData(IOUtil.PRODUCTTYPEPATH.getPath());
        result = result.substring(result.indexOf("[")+1,result.lastIndexOf("]"));
        String[] names = result.split(",");
        ProductTypeModel productTypeModel = new ProductTypeModel();
        for (int i = 0; i < names.length; i++) {
            ProductTypeModel productType = new ProductTypeModel();
            productType.setName(names[i].trim());
//            productType.setHref(hrefs[i]);
            productTypeModel.list.add(productType);
            System.out.println(names[i].trim());
        }
        return productTypeModel.list;
    }

    public static void main(String[] args) {
        new ProductTypeService().getProductTypeList();
    }
}
